package com.jiyun.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.jiyun.mapper.ManagementMapper;
import com.jiyun.model.management.Management;
import com.jiyun.model.management.ManagementVO;
import com.jiyun.result.Result;
import com.jiyun.service.ManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Management")
@CrossOrigin
@Api(tags = "服务管理")
public class ManagementController {
    @Autowired
    ManagementService managementService;
    @Autowired
    ManagementMapper managementMapper;


    @ApiOperation("查询")
    @RequestMapping("findAll")
    public IPage<ManagementVO> findAll(Integer current, Integer size, @RequestBody ManagementVO vo){

      return managementService.findAll(current,size,vo);
    }

    @ApiOperation("添加")
    @RequestMapping("add")
    public Boolean add(@RequestBody Management management){
        return managementService.add(management);
    }
    @RequestMapping("get/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.ok(managementService.getById(id));
    }
    @ApiOperation("修改")
    @RequestMapping("update")
    public Result update(@RequestBody Management management){
        managementMapper.updateById(management);
        return Result.ok();

    }
    @ApiOperation("服务修改")
    @PostMapping("/updateSstatus")
    public Result updateSstatus(@RequestBody Management management){
        if (management.getSstatus().equals(1)){
            management.setSstatus(2);
        }
        managementMapper.updateById(management);
        return Result.ok();
    }
    @ApiOperation("驳回修改")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody Management management){
        if (management.getSstatus().equals(1)){
            management.setSstatus(3);
        }
           managementMapper.updateById(management);
        return Result.ok();
    }
    @ApiOperation("完成")
    @PostMapping("/updateFinish")
    public Result updateFinish(@RequestBody Management management){
        if (management.getSstatus().equals(2)){
            management.setSstatus(4);
        }
        managementMapper.updateById(management);
        return Result.ok();
    }
    @ApiOperation("取消")
    @PostMapping("/updateCancel")
    public Result updateCancel(@RequestBody Management management){
        if (management.getSstatus().equals(2)){
            management.setSstatus(5);
        }
        managementMapper.updateById(management);
        return Result.ok();
    }

    @ApiOperation("驳回原因")
    @PostMapping("/updateSoverrule")
    public Result updateSoverrule(@RequestBody Management management){
        managementMapper.updateById(management);
        return Result.ok();
    }


}
